package cn.com.dhc.danlu.business.favorite;


import java.util.List;

import cn.com.dhc.danlu.delegate.delegate.list.BaseListDataDelegate;
import cn.com.dhc.danlu.dlware.OperatorUtils;
import cn.com.hd.mall.web.webservices.entity.BaseResponse;
import cn.com.hd.mall.web.webservices.entity.freedom.request.base.BasePageRequest;
import cn.com.hd.mall.web.webservices.entity.response.mydl.favorite.FavoriteListResponse;
import rx.Observable;

import static cn.com.dhc.danlu.dlware.global.DanluApplication.agent;

/**
 * @Author: nieqigang@danlu.com
 * @Date: 2017.3.31
 */
public class FavoriteListDelegate extends BaseListDataDelegate<IFavoriteListDataCallback> {
    private static final int REQUEST_ROWS = 10;

    @Override
    public void onRefresh(boolean isRefresh) {
        mViewBridge.beforeRefresh();
        super.onRefresh(isRefresh);
    }

    @Override
    protected Observable createRequestObservable(int page) {
        BasePageRequest request = new BasePageRequest();
        request.setToken(agent.getToken());
        request.setPage(page);
        request.setRows(REQUEST_ROWS);

        return agent.getApi().getFavouriteList(request)
                .compose(OperatorUtils.<FavoriteListResponse>defaultSchedulers());
    }

    @Override
    protected List excavateList(BaseResponse model) {
        return ((FavoriteListResponse)model).getFavoriteList();
    }
}
